package com.four.bmm.util;


import com.alibaba.fastjson.JSON;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class JsonUtil {
    public static void toJson(HttpServletResponse response, Object object) {

        response.setContentType("text/html; charset=UTF-8");
        response.setHeader("Pragma", "no-cache");//禁止缓存，保证每次数据最新
        response.setHeader("Cache-Control", "no-cache");
        response.setDateHeader("Expires", 10);
        PrintWriter out = null;
        try {
            out = response.getWriter();
        } catch (IOException e) {
            e.printStackTrace();
        }
        String jsonStr = JSON.toJSONString(object);//将传入的数据转换成JSON格式输出
        out.print(jsonStr);
        out.flush();


    }
}
